package com.cgbl.service.vm

import android.app.Application
import androidx.databinding.ObservableField
import api.WorkServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.configs.AppConstants
import com.robot.base.model.TeamListBean
import com.robot.base.util.arouter.ARouterUtil
import com.tencent.open.apireq.BaseResp
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import com.robot.base.model.BaseResponse
import com.robot.base.model.PageListBean
import com.robot.base.model.ProjectBean

class HomeViewModel(application: Application) : GLBaseViewModel(application) {

    val teamTotalText = ObservableField<String>()

    val toProjectList = BindingCommand<Any>(BindingAction {
        ARouterUtil.goToActivity(AppConstants.Router.Project.A_PROJECT_LIST)
    })
    val uc = UIChangeEvent()

    class UIChangeEvent {

        val homeTeamDataEvent = SingleLiveEvent<List<TeamListBean>>()

    }

    fun fetchHomeTeam() {
        WorkServiceFactory.listTeam().subscribe(object :
            AbstractViewModelSubscriber<BaseResponse<List<TeamListBean>>>(this) {
            override fun onNext(t: BaseResponse<List<TeamListBean>>) {
                uc.homeTeamDataEvent.postValue(t.data)
                teamTotalText.set("总计${t.data.size}个")
            }
        })
    }


}